package com.hotelsystem.dao;

import com.hotelsystem.pojo.Orders;
import org.apache.ibatis.annotations.*;

import java.sql.Timestamp;
import java.util.List;
import java.util.Map;

public interface OrdersMapper {

    /**
     * 按条件查询全部订单信息及明细信息
     * @param map 条件集合
     * @return
     * @throws Exception
     */
    List<Orders> list(Map<String,Object> map) throws Exception;

    /**
     * 取消预定
     * @param ordersId 订单编号
     * @param statusId 状态编号
     * @return
     * @throws Exception
     */
    @Update("update t_orders set status_id = #{statusId} where orders_id = #{ordersId}")
    Integer update(@Param("ordersId") String ordersId, @Param("statusId") Integer statusId) throws Exception;

    /**
     * 添加订单
     * @return
     * @throws Exception
     */
    @Insert("insert into t_orders values(#{ordersId},#{customer.customerId},#{room.roomId},#{reservedDate},#{checkInDate},#{checkOutDate},#{liberateDate},#{totalMoney},#{repayMoney},#{status.statusId})")
    @Options(useGeneratedKeys = true,keyProperty = "ordersId",keyColumn = "orders_id")
    Integer insert(Orders orders) throws Exception;

    /**
     * 删除订单
     * @param ordersId 订单编号
     * @return
     */
    @Delete("delete from t_orders where orders_id = #{ordersId}")
    Integer delete(String ordersId) throws Exception;

    /**
     * 根据身份证号模糊查询客户的订单信息，没有订单的客户也一并查询出来
     * @return
     * @throws Exception
     */
    List<Orders> listByOrdersStatus(String idNumber) throws Exception;

    /**
     * 修改订单信息
     * @param orders
     * @return
     */
    @Update("update t_orders set check_in_date = #{checkInDate},check_out_date = #{checkOutDate},liberate_date = #{liberateDate},total_money = #{totalMoney},repay_money = #{repayMoney},status_id = #{status.statusId} where orders_id = #{ordersId}")
    Integer updateAll(Orders orders) throws Exception;

    /**
     * 根据订单号模糊查询入住中的订单
     * @param ordersId
     * @return
     * @throws Exception
     */
    List<Orders> listByOrdersId(String ordersId) throws Exception;


    public List<Orders> selectShuJuTongJi(@Param("min") Timestamp min, @Param("max")Timestamp max);

}